{% if env == "production" %}
{%   for release in ("10", "20", "30") %}
apiVersion: batch/v1
kind: CronJob
metadata:
  name: "stats-{{ release }}"
spec:
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 2
  concurrencyPolicy: Forbid
  schedule: "0 2 */16 * *"
  startingDeadlineSeconds: 500
  jobTemplate:
    spec:
      backoffLimit: 0
      template:
        metadata:
          labels:
            parent: "cron_stats"
        spec:
{% filter indent(width=10, first=True) %}
{%     include "cron_template.yml" %}
{% endfilter %}
---
{%   endfor %}
{% endif %}
{% set release="36" %}
apiVersion: batch/v1
kind: CronJob
metadata:
  name: "stats-latest"
spec:
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 2
  concurrencyPolicy: Forbid
  schedule: "0 4 * * *"
  startingDeadlineSeconds: 500
  jobTemplate:
    spec:
      backoffLimit: 0
      template:
        metadata:
          labels:
            parent: "cron_stats"
        spec:
{% filter indent(width=10, first=True) %}
{%     include "cron_template.yml" %}
{% endfilter %}
---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: build-website
spec:
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 2
  concurrencyPolicy: Forbid
  schedule: "0 */2 * * *"
  startingDeadlineSeconds: 500
  jobTemplate:
    spec:
      backoffLimit: 0
      template:
        metadata:
          labels:
            parent: "cron_website"
        spec:
          volumes:
          - name: srpm-data
            persistentVolumeClaim:
              claimName: "languages-storage{{ '-stg' if env == 'staging' else '' }}"
          restartPolicy: Never
          containers:
          - name: stats
            image: "image-registry.openshift-image-registry.svc:5000/languages/builder:latest"
            imagePullPolicy: Always
            command: ["/bin/sh", "-c"]
            args:
            - >
              for rel in $(ls -1d results/f*); do 
                ./build_website.py -v --results $(basename ${rel}) ;
              done ;
              cd website && hugo -D -d /src/results/public --noTimes --baseURL https://languages{{ env_suffix }}.fedoraproject.org
            volumeMounts:
            - name: srpm-data
              readOnly: false
              mountPath: /src/results
            resources:
              requests:
                cpu: '0'
                memory: 4Gi
---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: stats-website
spec:
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 2
  concurrencyPolicy: Forbid
  schedule: "0 * * * *"
  startingDeadlineSeconds: 500
  jobTemplate:
    spec:
      backoffLimit: 0
      template:
        metadata:
          labels:
            parent: "cron_website_stats"
        spec:
          restartPolicy: Never
          containers:
          - image: docker.io/allinurl/goaccess
            name: goaccess
            imagePullPolicy: IfNotPresent
            args:
            - "-a"
            - "--log-format=COMBINED"
            - "--log-file=/html/logs/access.log"
            - "--output=/html/public/stats.html"
            ports:
            volumeMounts:
            - name: nginx-data
              mountPath: /html
          volumes:
          - name: nginx-data
            persistentVolumeClaim:
              claimName: "languages-storage{{ '-stg' if env == 'staging' else '' }}"
